export const WIDGET_PREFIX = `Widget-`;
const widgets: Record<string, any> = import.meta.glob(
  ["./widgets/**/*.vue", "./widgets/**/*.tsx"],
  { eager: true }
);

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
export const widgetMap = Object.values<Record<string, any>>(widgets).reduce(
  (map: { [k: string]: any }, widget: any) => {
    const type = widget.default.widgetType;
    map[`${WIDGET_PREFIX}${type}`] = widget.default as any;
    return map;
  },
  {} as { [k: string]: any }
);

const settings: Record<string, any> = import.meta.glob(
  "./widgets/**/settings.ts",
  { eager: true }
);

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
export const settingMap: Record<string, any> = Object.values<
  Record<string, any>
>(settings).reduce((map: any, module: any) => {
  const ClassName = module.default;
  map[`${WIDGET_PREFIX}${ClassName.widgetType}`] = new ClassName();
  return map;
}, {} as Record<string, any>);
